package es.udc.emarketapp.http.view.actionForms;

import es.udc.fbellas.j2ee.util.struts.action.DefaultActionForm;
import es.udc.fbellas.j2ee.util.struts.action.PropertyValidator;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;

public class LoginForm extends DefaultActionForm {

    private String loginName;
    private String password;
    private boolean rememberMyPassword;
    private String type;
    private boolean shoppingCart;

    public LoginForm() {
        reset();
    }

    public String getLoginName() {
        return loginName;
    }

    public void setLoginName(String loginName) {
        this.loginName = loginName.trim();
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public boolean getRememberMyPassword() {
        return rememberMyPassword;
    }

    public void setRememberMyPassword(boolean rememberMyPassword) {
        this.rememberMyPassword = rememberMyPassword;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public boolean isShoppingCart() {
        return shoppingCart;
    }

    public void setShoppingCart(boolean shoppingCart) {
        this.shoppingCart = shoppingCart;
    }

    public void reset(ActionMapping mapping, HttpServletRequest request) {
        reset();
    }

    public ActionErrors validate(ActionMapping mapping,
            HttpServletRequest request) {

        ActionErrors errors = new ActionErrors();

        PropertyValidator.validateMandatory(errors, "loginName", loginName);
        PropertyValidator.validateMandatory(errors, "password", password);
       // PropertyValidator.validateMandatory(errors, "loginBy", loginBy);

        return errors;

    }

    private void reset() {
        loginName = null;
        password = null;
        rememberMyPassword = false;
        type = null;
    }
}
